package com.solution.dao;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.solution.exception.DAOException;
import com.solution.model.PO;
import com.solution.model.UserRolePermission;

/**
 * Exposes the CRUD functionalities for Role related table.
 * 
 *
 */
public class UserRolePermissionDAOImpl extends DAOImpl<UserRolePermission> implements UserRolePermissionDAO{

	
	/**
	 * Logger static object.
	 */
	private Logger log = Logger.getLogger(UserRolePermissionDAOImpl.class.getName());
	
	@Override
	protected Class<? extends PO> getPOClass() {
		return UserRolePermission.class;
	}	
	
	/**
	 * Delete the permissions entry from User_role_permission table
	 */
	public int deleteAllPermissionForRole(Long roleID)  throws DAOException {
		log.debug("Entering :: UserRolePermissionDAOImpl:getUserDetail()");
		try {
		String hql = "delete UserRolePermission where User_Role_typeID = :roleId";
        Query query = getCurrentSession().createQuery(hql);
        query.setLong("roleId",roleID);                
        int rowCount= query.executeUpdate();
        flushSession();
        return rowCount;
		}
		catch(HibernateException he){
			log.error(he, he);
			throw new DAOException(he);
		}
	}
}
